import http from "./http";

// 获取今日新闻 & 轮播图数据
const queryNewsLatest = () => http.get('/news_latest');

// 获取往日新闻
const queryNewsBefore = time => {
    return http.get('/news_before', {
        params: {
            time
        }
    });
};

// 获取新闻详细信息
const queryNewsInfo = id => {
    return http.get('/news_info', {
        params: {
            id
        }
    });
};

// 获取新闻的评论数据
const queryStoryExtra = id => {
    return http.get('/story_extra', {
        params: {
            id
        }
    });
};

// 登录
const login = (phone, code) => {
    return http.post('/login', {
        phone,
        code
    });
};

// 发送验证码
const phoneCode = phone => {
    return http.post('/phone_code', {
        phone
    });
};

// 获取登录者信息
const queryUserInfo = () => http.get('/user_info');

// 修改用户信息
const setUserUpdate = (username, file) => {
    let fm = new FormData();
    fm.append('username', username);
    fm.append('file', file);
    return http.post('/user_update', fm);
};

// 收藏新闻
const store = newsId => {
    return http.post('/store', { newsId });
};

// 移除收藏
const storeRemove = id => {
    return http.get('/store_remove', {
        params: {
            id
        }
    });
};

// 获取收藏列表 
const storeList = () => http.get('/store_list');

export default {
    queryNewsLatest,
    queryNewsBefore,
    queryNewsInfo,
    queryStoryExtra,
    login,
    phoneCode,
    queryUserInfo,
    setUserUpdate,
    store,
    storeRemove,
    storeList
};